package com.hmall.trade.config;

import com.hmall.common.constants.MqConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ljc
 * @version V1.0
 * @date 2025-03-21 20:00
 */
@Configuration
public class MqConfig {

    @Bean
    public Queue tradeQueue() {
        return QueueBuilder.durable(MqConstants.TRADE_QUEUE)
                .deadLetterExchange(MqConstants.DELAY_EXCHANGE_NAME)
                .deadLetterRoutingKey(MqConstants.DELAY_QUEUE)
                .ttl(60000)
                .build();
    }

    @Bean
    public DirectExchange tradeExchange() {
        return ExchangeBuilder.directExchange(MqConstants.TRADE_EXCHANGE_NAME).build();
    }

    @Bean
    public Binding tradeQueueTotradeExchange(Queue tradeQueue, Exchange tradeExchange ){
    return BindingBuilder.bind(tradeQueue)
            .to(tradeExchange)
            .with(MqConstants.DELAY_KEY).noargs();

    }
}
